import {
  registerApplication,
  start
} from "single-spa"
import {
  initGlobalState,
  initChildState
} from './utils/global'

const global = initGlobalState({
  count: 1
})
const childState =new initChildState(global)
// 注册微应用
registerApplication({
  name: "@single-spa/welcome",
  app: () =>
    System.import(
      "https://unpkg.com/single-spa-welcome/dist/single-spa-welcome.js"
    ),
  // 激活微应用的路径
  activeWhen: location => location.pathname === '/',
});

registerApplication({
  name: "@learn/html",
  app: () => System.import("@learn/html"),
  activeWhen: ["/html"]
});
registerApplication({
  name: "@learn/react",
  app: () => System.import("@learn/react"),
  activeWhen: ["/react"],
  customProps: {
    onGlobalStateChange: childState.onGlobalStateChange.bind(global),
    setGlobalState: childState.setGlobalState.bind(global),
    offGlobalState: childState.offGlobalState.bind(global)
  }
});
registerApplication({
  name: "@learn/vue3",
  app: () => System.import("@learn/vue3"),
  activeWhen: ["/vue3"]
});
registerApplication({
  name: "@learn/vue",
  app: () => System.import("@learn/vue"),
  activeWhen: ["/vue"]
})
registerApplication({
  name: "@learn/parcel-vue",
  app: () => System.import("@learn/parcel-vue"),
  activeWhen: ["/parcel-vue"]
})
registerApplication({
  name: "@learn/utility-test",
  app: () => System.import("@learn/utility-test"),
  activeWhen: ["/utility-test"]
})
start({
  urlRerouteOnly: true,
});